/* This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package com.l2jfrozen.gameserver.model.zone.type;

import java.util.Collection;
import java.util.concurrent.ScheduledFuture;

import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
import com.l2jfrozen.gameserver.datatables.SkillTable;
import com.l2jfrozen.gameserver.model.L2Character;
import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
import com.l2jfrozen.gameserver.model.actor.instance.L2SummonInstance;
import com.l2jfrozen.gameserver.model.zone.L2ZoneType;

import com.l2jfrozen.util.random.Rnd;

/**
 * @author l2dot
 */
public class L2HotSpringWater extends L2ZoneType 
{
	private ScheduledFuture<?> _task;
	public L2HotSpringWater(int id) 
	{
		super(id);
	}
	
	@Override
	public void setParameter(String name, String value) 
	{
		super.setParameter(name, value);
	}
	
	@Override
	protected void onEnter(L2Character character) 
	{
		if (character instanceof L2PcInstance) 
		{
			SkillTable.getInstance().getInfo(4559, 1).getEffects(character, character);
		}
		if (_task == null) 
		{
			_task = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new RemoveEffect(this), 0, 5000);
		}
	}

	protected Collection<L2Character> getCharacterList() 
	{
		return _characterList.values();
	}

	class RemoveEffect implements Runnable 
	{
		private L2HotSpringWater _poisonZone;
		private int _zoneId;
		RemoveEffect(L2HotSpringWater zone) 
		{
			_poisonZone = zone;
			_zoneId = zone.getId();
		}
		
		public void run() 
		{
			if (Rnd.get(100) < 40) 
			{
				for (L2Character temp : _poisonZone.getCharacterList()) 
				{
					switch (_zoneId) 
					{
						case 60030://red  Skill: 4552, 4554
						case 60031:
						temp.stopSkillEffects(4552);
						temp.stopSkillEffects(4554);
						break;
						case 60032://yellow Skill: 4551, 4554
						temp.stopSkillEffects(4551);
						temp.stopSkillEffects(4554);
						break;
						case 60033://green Skill: 4553, 4554
						temp.stopSkillEffects(4553);
						temp.stopSkillEffects(4554);
						break;
					}
				}
			}
		}
	}

	@Override
	protected void onExit(L2Character character) 
	{
		if ((character instanceof L2PcInstance) || (character instanceof L2SummonInstance)) 
		{
			character.stopSkillEffects(4559);
		}
		if (_characterList.isEmpty() && _task != null) 
		{
			_task.cancel(true);
			_task = null;
		}
	}

	@Override
	protected void onDieInside(L2Character character) 
	{}

	@Override
	protected void onReviveInside(L2Character character) 
	{}
}